namespace System.Collections.Generic;
/// <summary>
/// IEnumerableExtensions
/// </summary>
public static class IEnumerableExtensions
{
    /// <summary>
    /// 
    /// </summary>
    public static bool TryGetValue<TResult, T>(
        this IEnumerable<TResult> enumerables,
        Func<TResult, bool> predicate,
        out T result,
#pragma warning disable CS8601 // Possible null reference assignment.
        T defaultValue = default)
#pragma warning restore CS8601 // Possible null reference assignment.
    {
        try
        {
            result = (T)Convert.ChangeType(enumerables.First(predicate), typeof(T));

            return true;
        }
        catch (Exception)
        {
            result = defaultValue;
            return false;
        }
    }
}